
//
//  newViewController.m
//  qqq
//
//  Created by 魏春生 on 15/8/13.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "newViewController.h"
#import "cellTableViewCell.h"
#import "newsViewController.h"
#define height 59
#define  USER_ID 24
@interface newViewController ()
<UIAlertViewDelegate>
@end

@implementation newViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSUserDefaults standardUserDefaults]setValue:@"魏春生" forKey:@"name"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"name"];
    NSString*qqq;
    int i=2;
    int k=3;
    qqq = i>k?@"大于":@"小于";
    
    
    
    

    _rrr = @[
           @{
               @"header": @"宝骏560即将耀目登场1",
               @"foot": @"宝骏560即将耀目登场2",
               @"list": @[
                       @{
                           @"title": @"哈哈",
                           @"content": @"呵呵",
                           },
                       @{
                           @"title": @"哈哈",
                           @"content": @"宝骏560即将耀目登场",
                           }
                       ]
               },
                                           @{
               @"headerTitle": @"哈哈",
               @"footTitle": @"呵呵",
               @"list": @[
                       @{
                           @"title": @"哈哈",
                           @"content": @"呵呵",
                           @"date": @"2014-06-08"
                           },
                       @{
                           @"title": @"呵呵",
                           @"content": @"哈哈",
                           }
                       ]
               }
           ];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary*dic = [_rrr objectAtIndex:section];
    NSArray *arr = dic[@"list"];
    return arr.count;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    cellTableViewCell*cell = [[[NSBundle mainBundle]loadNibNamed:@"cellTableViewCell" owner:self options:nil]lastObject];
    NSDictionary*dic1= [_rrr objectAtIndex:indexPath.section];
    NSArray*arr = dic1 [@"list"];
    NSDictionary*dic2 = [arr objectAtIndex:indexPath.row];
    cell.bbb.text = dic2[@"title"];
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _rrr.count;
}



- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView*view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, 320, 59);
    view.backgroundColor = [UIColor yellowColor];
    UILabel*lebel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 21)];
    NSDictionary*dic3=[_rrr objectAtIndex:section];
    lebel.text= dic3[@"header"];
    [view addSubview:lebel];
    
        return view;

}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView*view1 = [[UIView alloc]init];
    view1.frame = CGRectMake(290, 24, 21, 21);
    view1.backgroundColor = [UIColor redColor];
    UILabel*lebel1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 21)];
    NSDictionary*dic4 = [_rrr objectAtIndex:section];
    lebel1.text = dic4[@"foot"];
    [view1 addSubview:lebel1];
    return view1;

}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return height;
}




- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"WillAppear");
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"DidAppear");
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    NSLog(@"WillDisappear");
    
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    NSLog(@"DidDisappear");
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    newsViewController *vc = [[newsViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
    UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要退出吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    [alrt show];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{if (buttonIndex==0){NSLog(@"点击了取消");}else
{
    NSLog(@"点击了确定");
}






}@end
